<!DOCTYPE html>
<!--
     SPDX-License-Identifier: CC-BY-SA-4.0
     SPDX-FileCopyrightText: 2020 seL4 Project a Series of LF Projects, LLC.
-->
<!-- Page last generated 2025-02-20 03:16:15 +0000 -->
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>libsel4vmmplatsupport_guest_memory_util | seL4 docs</title>

    <!-- Our stylesheet and theme stylesheet.  Contains bootstrap. -->
    <link rel="stylesheet" href="/assets/css/style.css" type="text/css">
    <!-- Font awesome -->
    <link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
    <!-- Pygments syntax highlighting  -->
    <link rel="stylesheet" href="/assets/css/highlighting/trac.css" type="text/css">
    <link rel="icon" type="image/x-icon" href="/assets/favicon.ico"><script defer data-domain="docs.sel4.systems"
	    src="https://analytics.sel4.systems/js/script.js"></script></head>

  <body class="container-fluid">

    



<header>
  <ul class="row menu">
    <li class="col-xs-12 col-md-2" >
            <a href="https://sel4.systems" class="skip-icon">
              <img class="img-responsive" src="/assets/logo-text-white.svg" alt="seL4 logo" />
            </a>
    </li>
    <li class="col-xs-12 col-md-10 menu">
      <nav aria-label="Banner links">
        <h2><a href="/Resources" />Resources</h2>
        <h2><a href="/processes" />Contributing</a></h2>
        <h2><a href="/projects" />Projects</h2>
        <h2><a href="/Tutorials" />Tutorials</h2>
        <iframe title="DuckDuckGo search bar" src="https://duckduckgo.com/search.html?site=docs.sel4.systems&prefill=Search%20sel4.systems" style="overflow:hidden;margin-bottom:10px; padding:0;height:40px;float:right;border-width: 0px"></iframe>
      </nav>
    </li>
  </ul>
  <div class="clear"></div>
  
<div class="breadcrumbs bootstrap hidden-sm-down">
  <nav class="sel-breadcrumb" aria-label="Breadcrumb" >
    <ol class=" list-unstyled" vocab="http://schema.org/" typeof="BreadcrumbList">
      
      
        

        

        <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <a property="item" typeof="WebPage" href="/">
              <span property="name"><b>seL4 Docs</b></span>
            </a>
            <meta property="position" content="1" />
        </li>
      
        

        

        <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <a property="item" typeof="WebPage" href="/projects/">
              <span property="name"><b>Projects</b></span>
            </a>
            <meta property="position" content="2" />
        </li>
      
        

        

        <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <a property="item" typeof="WebPage" href="/projects/virtualization/">
              <span property="name"><b>Virtualisation on seL4</b></span>
            </a>
            <meta property="position" content="3" />
        </li>
      
        

        

        <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <a property="item" typeof="WebPage" href="/projects/virtualization/docs/">
              <span property="name"><b>libsel4vm & libsel4vmmplatsupport API documentation</b></span>
            </a>
            <meta property="position" content="4" />
        </li>
      
        

        
          <li class="breadcrumb-item" property="itemListElement" typeof="ListItem">
            <span property="name">libsel4vmmplatsupport_guest_memory_util</span>
            <meta property="position" content="5" /></li>
          
    </ol>
  </nav>
  <nav class="sel-version" aria-label="Current Versions">
    <ol class="list-unstyled">
      <li class="list-unstyled text-right" style="margin-left:auto; padding:0rem 0rem;">
        Current versions:</li>
      <li class="list-unstyled text-right">
      <a href="/releases/sel4/13.0.0"><b>seL4-13.0.0</b></a></li>
      <li class="list-unstyled text-right">
      <a href="/releases/microkit/1.4.1"><b>microkit-1.4.1</b></a></li>
      <li class="list-unstyled text-right">
      <a href="/releases/camkes/camkes-3.11.0"><b>camkes-3.11.0</b></a></li>
      <li class="list-unstyled text-right">
      <a href="/releases/capdl/0.3.0"><b>capDL-0.3.0</b></a></li>
      </ol>
  </nav>
  <div class='clear'></div>
</div>


</header>

    <main>
      <div class="row">
  <div class="hidden-xs col-sm-4 col-md-3 col-lg-2">
    


<div class="sidebar">















    <ul class="nav nav-sidebar">
  
    
    

    
        <li class="">
            <a class="" href="/projects/sel4/">seL4</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/l4v/">L4.verified</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/camkes/">CAmkES</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/capdl/">CapDL</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/elfloader/">Elfloader</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/buildsystem/">seL4 Buildsystem</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/user_libs/">user_libs</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/sel4runtime/">The seL4 run-time</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/sel4webserver/">seL4webserver</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/sel4-tutorials/">seL4 tutorials</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/sel4bench/">sel4bench</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/sel4test/">seL4Test</a>
        </li>
  
    
    

    
        <li class="active">
            <a class="" href="/projects/virtualization/">Virtualization</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/camkes-vm/">camkes-vm</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/dockerfiles/">Dockerfiles</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/docsite/">seL4 Documentation website</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/sel4_tools/">seL4_tools</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/microkit/">Microkit</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/hardware_hacks/">Hardware Hacks</a>
        </li>
  
    
    

    
        <li class="">
            <a class="" href="/projects/rust/">Rust</a>
        </li>
  
    </ul>


</div>

  </div>
  <div class="content col-sm-8 col-md-6 col-lg-7 main">
    <!--
     Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)

     SPDX-License-Identifier: CC-BY-SA-4.0
-->

<h2 id="interface-guest_memory_utilh">Interface <code class="language-plaintext highlighter-rouge">guest_memory_util.h</code></h2>

<p>The guest memory util interface provides various utilities and helpers for using the libsel4vm guest memory
interface. The methods in the interface cover common usage patterns when managing memory for a VM instance.</p>

<h3 id="brief-content">Brief content:</h3>

<p><strong>Functions</strong>:</p>

<blockquote>
  <p><a href="#function-create_allocated_reservation_framevm-addr-rights-alloc_fault_callback-alloc_fault_cookie"><code class="language-plaintext highlighter-rouge">create_allocated_reservation_frame(vm, addr, rights, alloc_fault_callback, alloc_fault_cookie)</code></a></p>
</blockquote>

<blockquote>
  <p><a href="#function-create_device_reservation_framevm-addr-rights-fault_callback-fault_cookie"><code class="language-plaintext highlighter-rouge">create_device_reservation_frame(vm, addr, rights, fault_callback, fault_cookie)</code></a></p>
</blockquote>

<blockquote>
  <p><a href="#function-map_ut_alloc_reservation_with_base_paddrvm-paddr-reservation"><code class="language-plaintext highlighter-rouge">map_ut_alloc_reservation_with_base_paddr(vm, paddr, reservation)</code></a></p>
</blockquote>

<blockquote>
  <p><a href="#function-map_ut_alloc_reservationvm-reservation"><code class="language-plaintext highlighter-rouge">map_ut_alloc_reservation(vm, reservation)</code></a></p>
</blockquote>

<blockquote>
  <p><a href="#function-map_frame_alloc_reservationvm-reservation"><code class="language-plaintext highlighter-rouge">map_frame_alloc_reservation(vm, reservation)</code></a></p>
</blockquote>

<blockquote>
  <p><a href="#function-map_maybe_device_reservationvm-reservation"><code class="language-plaintext highlighter-rouge">map_maybe_device_reservation(vm, reservation)</code></a></p>
</blockquote>

<h2 id="functions">Functions</h2>

<p>The interface <code class="language-plaintext highlighter-rouge">guest_memory_util.h</code> defines the following functions.</p>

<h3 id="function-create_allocated_reservation_framevm-addr-rights-alloc_fault_callback-alloc_fault_cookie">Function <code class="language-plaintext highlighter-rouge">create_allocated_reservation_frame(vm, addr, rights, alloc_fault_callback, alloc_fault_cookie)</code></h3>

<p>Create and map a reservation for a vka allocated frame. The allocated frame is mapped in both the vm and vmm vspace</p>

<p><strong>Parameters:</strong></p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">vm {vm_t *}</code>: A handle to the VM</li>
  <li><code class="language-plaintext highlighter-rouge">addr {uintptr_t}</code>: Address of emulated frame</li>
  <li><code class="language-plaintext highlighter-rouge">rights {seL4_CapRights_t}</code>: Rights for mapping the allocated frame into the vm’s vspace</li>
  <li><code class="language-plaintext highlighter-rouge">alloc_fault_callback {memory_fault_callback_fn}</code>: Fault callback for allocated frame</li>
  <li><code class="language-plaintext highlighter-rouge">alloc_fault_cookie {void *}</code>: Cookie for fault callback</li>
</ul>

<p><strong>Returns:</strong></p>

<ul>
  <li>Address of allocated frame in vmm vspace</li>
</ul>

<p>Back to <a href="#module-guest_memory_utilh">interface description</a>.</p>

<h3 id="function-create_device_reservation_framevm-addr-rights-fault_callback-fault_cookie">Function <code class="language-plaintext highlighter-rouge">create_device_reservation_frame(vm, addr, rights, fault_callback, fault_cookie)</code></h3>

<p>Create and map a reservation for a device frame. The device frame is mapped in both the vm and vmm vspace</p>

<p><strong>Parameters:</strong></p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">vm {vm_t *}</code>: A handle to the VM</li>
  <li><code class="language-plaintext highlighter-rouge">addr {uintptr_t}</code>: Address of emulated frame</li>
  <li><code class="language-plaintext highlighter-rouge">rights {seL4_CapRights_t}</code>: Rights for mapping the device frame into the vm’s vspace</li>
  <li><code class="language-plaintext highlighter-rouge">fault_callback {memory_fault_callback_fn}</code>: Fault callback for the frame</li>
  <li><code class="language-plaintext highlighter-rouge">fault_cookie {void *}</code>: Cookie for fault callback</li>
</ul>

<p><strong>Returns:</strong></p>

<ul>
  <li>Address of device frame in vmm vspace</li>
</ul>

<p>Back to <a href="#module-guest_memory_utilh">interface description</a>.</p>

<h3 id="function-map_ut_alloc_reservation_with_base_paddrvm-paddr-reservation">Function <code class="language-plaintext highlighter-rouge">map_ut_alloc_reservation_with_base_paddr(vm, paddr, reservation)</code></h3>

<p>Map a guest reservation backed with untyped frames allocated from a base paddr</p>

<p><strong>Parameters:</strong></p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">vm {vm_t *}</code>: A handle to the VM</li>
  <li><code class="language-plaintext highlighter-rouge">paddr {uintptr_t}</code>: Base paddr to allocate from</li>
  <li><code class="language-plaintext highlighter-rouge">reservation {vm_memory_reservation_t *}</code>: Pointer to reservation object being mapped</li>
</ul>

<p><strong>Returns:</strong></p>

<ul>
  <li>-1 on failure otherwise 0 for success</li>
</ul>

<p>Back to <a href="#module-guest_memory_utilh">interface description</a>.</p>

<h3 id="function-map_ut_alloc_reservationvm-reservation">Function <code class="language-plaintext highlighter-rouge">map_ut_alloc_reservation(vm, reservation)</code></h3>

<p>Map a guest reservation backed with untyped frames</p>

<p><strong>Parameters:</strong></p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">vm {vm_t *}</code>: A handle to the VM</li>
  <li><code class="language-plaintext highlighter-rouge">reservation {vm_memory_reservation_t *}</code>: Pointer to reservation object being mapped</li>
</ul>

<p><strong>Returns:</strong></p>

<ul>
  <li>-1 on failure otherwise 0 for success</li>
</ul>

<p>Back to <a href="#module-guest_memory_utilh">interface description</a>.</p>

<h3 id="function-map_frame_alloc_reservationvm-reservation">Function <code class="language-plaintext highlighter-rouge">map_frame_alloc_reservation(vm, reservation)</code></h3>

<p>Map a guest reservation backed with free vka frames</p>

<p><strong>Parameters:</strong></p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">vm {vm_t *}</code>: A handle to the VM</li>
  <li><code class="language-plaintext highlighter-rouge">reservation {vm_memory_reservation_t *}</code>: Pointer to reservation object being mapped</li>
</ul>

<p><strong>Returns:</strong></p>

<ul>
  <li>-1 on failure otherwise 0 for success</li>
</ul>

<p>Back to <a href="#module-guest_memory_utilh">interface description</a>.</p>

<h3 id="function-map_maybe_device_reservationvm-reservation">Function <code class="language-plaintext highlighter-rouge">map_maybe_device_reservation(vm, reservation)</code></h3>

<p>Map a guest reservation backed with device frames</p>

<p><strong>Parameters:</strong></p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">vm {vm_t *}</code>: A handle to the VM</li>
  <li><code class="language-plaintext highlighter-rouge">reservation {vm_memory_reservation_t *}</code>: Pointer to reservation object being mapped</li>
</ul>

<p><strong>Returns:</strong></p>

<ul>
  <li>-1 on failure otherwise 0 for success</li>
</ul>

<p>Back to <a href="#module-guest_memory_utilh">interface description</a>.</p>

<p>Back to <a href="#">top</a>.</p>


  </div>







  
  
<div class="sidebar-toc hidden-xs hidden-sm col-md-3 col-lg-3">
  
    <ul class="section-nav">
    	<h2> Virtualization </h2> 
        <li>
          
          <a style="" class="" href="/projects/virtualization/">
            Documentation homepage
          </a>
        </li>

















    
        <h3>Repositories</h3>
    
        <li>
          <a class="" href="https://github.com/seL4proj/seL4_projects_libs">
            seL4_projects_libs
          </a>
        </li>









  







    </ul>

</div>


</div>

    </main>
    


<footer class="site-footer">

  <h2 class="footer-heading">seL4 docs</h2>

  <div class="footer-col-wrapper">

    <div class="col-md-2">
      



<ul class="social-media-list">
  <li><a href="https://github.com/sel4"><i class="fab fa-github"></i> <span class="username">sel4</span></a></li><li><a href="https://github.com/sel4proj"><i class="fab fa-github"></i> <span class="username">sel4proj</span></a></li>
</ul>

    </div>

    <div class="col-md-8">
      <ul class="list-unstyled">
        <li>
          This site is for displaying seL4 related documentation.  Pull requests are welcome.
        </li>
        
          <li>
            Site last updated: Fri Feb 7 10:17:38 2025 +1100 ee78c8857c
          </li>
          <li>
                Page last updated: 
          </li>
        
      </ul>
    </div>
    <div class="col-md-2">
<a href="https://github.com/seL4/docs/blob/master/projects/virtualization/docs/api/libsel4vmmplatsupport_guest_memory_util.md">View page on GitHub</a>
      <br />
      <a href="https://github.com/seL4/docs/edit/master/projects/virtualization/docs/api/libsel4vmmplatsupport_guest_memory_util.md">Edit page on GitHub</a>
      <br />
      <a href="/sitemap">Sitemap</a>
    </div>

  </div>

</footer>

  </body>
</html>
